package com.zq.thread.Observe;

public interface TaskLifececle<T> {


    // 任务启动时会触发onStart
    void onStart(Thread thread);

    //  任务正在进行时会触发onRunning
    void onRunning(Thread thread);

    //任务结束时会触发onFinish，result是任务执行结束的结果
    void onFinish(Thread thread, T result);

    //任务正执行报错会触发onError
    void onError(Thread thread, Exception exception);

    class EmptyLifecycle<T> implements TaskLifececle<T> {

        @Override
        public void onStart(Thread thread) {
            // do nothing
        }

        @Override
        public void onRunning(Thread thread) {
            // do nothing
        }

        @Override
        public void onFinish(Thread thread, T result) {
            // do nothing
        }

        @Override
        public void onError(Thread thread, Exception exception) {
            // do nothing
        }
    }

}
